<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('海报配置列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>海报标题：</label>
                            <input type="text" name="title"/>
                        </li>
                        <li>
                            <label>海报属性：</label>
                            <select name="attribute" onchange="attrChange(this.value);"
                                    th:with="type=${@dict.getType('ecard_poster_attribute')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>海报类目：</label>
                            <select name="posterType" id="posterType">
                                <option value="">所有</option>
                            </select>
                        </li>
                        <li>
                            <label>是否编辑：</label>
                            <select name="editSts"
                                    th:with="type=${@dict.getType('ecard_poster_edit_sts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>法人机构：</label>
                            <select name="deptId" id="deptId"
                                    th:with="type=${@dept.selectDeptListByType('2')}">
                                <option value="">所有</option>
                                <option th:each="dept : ${type}" th:text="${dept.deptName}"
                                        th:value="${dept.deptId}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="config:posterConfigure:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="config:posterConfigure:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="config:posterConfigure:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('config:posterConfigure:edit')}]];
    var removeFlag = [[${@permission.hasPermi('config:posterConfigure:remove')}]];
    var prefix = ctx + "config/posterConfigure";
    var deptIdDatas = [[${@dept.selectDeptListByType('2')}]];
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "海报配置",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'title',
                    title: '海报标题'
                },
                {
                    field: 'posterImg',
                    title: '海报图片',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.posterImg, 550, 274);
                    }
                },
                {
                    field: 'attribute',
                    title: '海报属性',
                    formatter: function (value, row, index) {
                        return attrTools(row);
                    }
                },
                {
                    field: 'posterType',
                    title: '海报类目',
                    formatter: function (value, row, index) {
                        return typeTools(row);
                    }
                },
                {
                    field: 'editSts',
                    title: '是否编辑',
                    formatter: function (value, row, index) {
                        return isEditTools(row);
                    }
                },
                {
                    field: 'deptId',
                    title: '法人机构',
                    formatter: function (value, row, index) {
                        return selectDeptName(deptIdDatas, value);
                    }
                },
                {
                    field: 'userName',
                    title: '创建人'
                },
                {
                    field: 'sts',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function selectDeptName(deptIdDatas, value) {
        if ($.common.isEmpty(deptIdDatas) || $.common.isEmpty(value)) {
            return '';
        }
        var actions = [];
        $.each(deptIdDatas, function (index, dept) {
            if (dept.deptId == ('' + value)) {
                var listClass = $.common.equals("default", dept.listClass) || $.common.isEmpty(dept.listClass) ? "" : "badge badge-" + dept.listClass;
                actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dept.deptName));
                return false;
            }
        });
        return actions.join('');
    }

    function attrChange(val) {
        var typeDatas = "";
        if (val == '1') {
            typeDatas = [[${@dict.getType('ecard_poster_curr_type')}]];
        } else {
            typeDatas = [[${@dict.getType('ecard_poster_bank_type')}]];
        }
        var str = '<option value="">所有</option>';
        for (var i = 0; i < typeDatas.length; i++) {
            str += '<option value="' + typeDatas[i].dictValue + '">' + typeDatas[i].dictLabel + '</option>';
        }
        $('#posterType').html(str);
    }

    /* 海报属性 */
    function attrTools(row) {
        if (row.attribute == 1) {
            return '通用海报';
        } else {
            return '行内海报';
        }
    }

    /* 海报类目 */
    function typeTools(row) {
        return '行内海报';
    }

    /* 是否编辑 */
    function isEditTools(row) {
        if (row.editSts == 2) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="isYesEdit(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="isNotEdit(\'' + row.id + '\')"></i> ';
        }
    }

    /* 海报编辑状态停用 */
    function isNotEdit(id) {
        $.modal.confirm("确认要启用编辑吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "editSts": 2});
        })
    }

    /* 海报编辑状态启用 */
    function isYesEdit(id) {
        $.modal.confirm("确认要启用编辑吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "editSts": 1});
        })
    }

    /* 状态显示 */
    function statusTools(row) {
        if (row.sts == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 状态停用 */
    function disable(id) {
        $.modal.confirm("确认要停用海报吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "sts": 0});
        })
    }

    /* 状态启用 */
    function enable(id) {
        $.modal.confirm("确认要启用海报吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "sts": 1});
        })
    }
</script>
</body>
</html>